#include <QtOpenGL>
#include <QVector3D>
#include "cubo.h"

Cubo::Cubo(const QVector3D& center, QObject *parent):
    Object3D(center, parent)
{

}

void Cubo::drawGeometry(void)const
{
    glFrontFace(GL_CW);
    origin();

    glBegin(GL_QUADS);

    // face - frente
    glColor3f(1.0, 1.0, 1.0);

    glNormal3f(0.0,0.0,-1.0);
        glVertex3i(1,0,0);
        glVertex3i(1,1,0);
        glVertex3i(0,1,0);
        glVertex3i(0,0,0);

        // face - tras
        glNormal3f(0,0,-1.0);
        glColor3f(0, 0, 1.0);

        glVertex3i(1,0,1);
        glVertex3i(0,0,1);
        glVertex3i(0,1,1);
        glVertex3i(1,1,1);

        glNormal3f(1.0,0,0);
        glVertex3i(0,1,0);
        glVertex3i(0,1,1);
        glVertex3i(0,0,1);
        glVertex3i(0,0,0);

        glColor3f(1.0, 0, 0);

        //face direita
        glNormal3f(-1.0,0,0);
        glVertex3i(1,1,0);
        glVertex3i(1,0,0);
        glVertex3i(1,0,1);
        glVertex3i(1,1,1);


        //face de baixo
        glColor3f(0, 1.0, 0);
        glNormal3f(0,-1.0,0);
        glVertex3i(1,1,0);
        glVertex3i(1,1,1);
        glVertex3i(0,1,1);
        glVertex3i(0,1,0);

        //face de cima
        glColor3f(0, 1.0, 1.0);
        glNormal3f(0,1.0,0);
        glVertex3i(1,0,0);
        glVertex3i(0,0,0);
        glVertex3i(0,0,1);
        glVertex3i(1,0,1);
    glEnd();


}

void Cubo::origin()const
{
    glDisable(GL_LIGHTING);
    glBegin(GL_LINES);
    glColor3f(1.0, 0, 0);
    glVertex3i(0, 0, 0);
    glVertex3i(1, 0, 0);

    glColor3f(0, 1.0, 0);
    glVertex3i(0, 0, 0);
    glVertex3i(0, 1, 0);

    glColor3f(0, 0, 1.0);
    glVertex3i(0, 0, 0);
    glVertex3i(0, 0, 1);
    glEnd();
    glEnable(GL_LIGHTING);
}
